<?php
/**
 * @author 天涯 <mail@phpha.com>
 * @copyright http://blog.phpha.com
 * @link http://blog.phpha.com/vncms
 * @version 1.0
 */
defined('APP_PATH') or exit('Access Denied');
class m_field extends spModel{
	public $table = 'field';
	public $pk = 'fieldid';
	//自动验证
	public $verifier = array(
		'rules'=>array(
			'field'=>array(
				'notnull'=>true,
			),
			'name'=>array(
				'notnull'=>true,
			),
			'modelid'=>array(
				'notnull'=>true,
			),
			'typeid'=>array(
				'notnull'=>true,
			),
		),
	);
	//关联模型表
	public $linker = array(
		array(
			'type'=>'hasone', //一对一关联
			'map'=>'model', //关联标识
			'mapkey'=>'modelid', //本表关联字段
			'fclass'=>'m_table', //对应表类名
			'fkey'=>'modelid', //对应表关联字段
			'enabled'=>true, //启用关联
		),
		array(
			'type'=>'hasone', //一对一关联
			'map'=>'type', //关联标识
			'mapkey'=>'typeid', //本表关联字段
			'fclass'=>'m_type', //对应表类名
			'fkey'=>'typeid', //对应表关联字段
			'enabled'=>true, //启用关联
		),
	);
	//检测字段
	public function check_field($field,$table){
		$fields = array();
		$query = $this->findSql("SHOW COLUMNS FROM " . $GLOBALS['G_SP']['db']['prefix'] . $table);
		foreach($query as $v){
			$fields[] = $v['Field'];
		}
		return in_array($field, $fields) ? 1 : 0;
	}
}
